﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace MySQLLib
{
    public class Char_items
    {
        string[,] _char_items;
        private MySqlConnection conn;

        public void refresh()
        {
            string[] columns = new string[1];
            columns[0] = "*";

            this._char_items = Query.SelectQuery(this.conn, "char_items", columns);
        }

        public void setConnection(MySqlConnection connection)
        {
            this.conn = connection;
        }

        public string[,] getItemsFromOwner(int owner, bool refresh = false)
        {
            if (refresh)
                this.refresh();

            string[,] items = new string[0, _char_items.GetLength(1)];

            for (int i = 0; i < this._char_items.GetLength(0); i++)
            {
                if (this._char_items[i, 1] == owner.ToString())
                {
                    Other.ResizetwoDimensArray(ref items, this._char_items.GetLength(1), this._char_items.GetLength(0) + 1);
                    for (int i2 = 0; i2 < this._char_items.GetLength(1); i2++)
                    {
                        items[items.GetLength(0) - 1, i2] = this._char_items[i, i2];
                    }
                }
            }

            return items;
        }
    }
}
